package com.dzt.androidframework.photo;

import android.os.Bundle;
import android.widget.ImageView;

import com.dzt.androidframework.R;
import com.dzt.androidframework.activity.ActivityTitle;

import org.xutils.common.util.DensityUtil;
import org.xutils.image.ImageOptions;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.io.File;

public class xUtilsActivity extends ActivityTitle {

	@ViewInject(R.id.iv1)
	private ImageView img1;
	@ViewInject(R.id.iv2)
	private ImageView img2;
	@ViewInject(R.id.iv3)
	private ImageView img3;
	@ViewInject(R.id.iv4)
	private ImageView img4;

	@Override
	protected int getLayoutId() {
		return R.layout.activity_x_utils;
	}

	@Override
	protected void initParams() {
		setTitleView(R.string.text_xutils);
		load1();

		load2();
	}

	@Override
	protected void initData(Bundle savedInstanceState) {

	}

	private void load1(){
		x.image().bind(img1, "http://img1.3lian.com/2015/w22/55/d/107.jpg");

		x.image().bind(img2, new File("storage/emulated/0/bimagechooser/magazine-unlock-01-2.3.551-bigpicture_01_41.jpg").getAbsolutePath());
	}

	private void load2(){
		//设置图片属性的options
		ImageOptions options = new ImageOptions.Builder()
				//设置图片的大小
				.setSize(300, 300)
				// 如果ImageView的大小不是定义为wrap_content, 不要crop.
				.setCrop(true)
				// 加载中或错误图片的ScaleType
				//.setPlaceholderScaleType(ImageView.ScaleType.MATRIX)
				.setImageScaleType(ImageView.ScaleType.CENTER_CROP)
				//设置加载过程中的图片
				.setLoadingDrawableId(R.mipmap.ic_launcher)
				//设置加载失败后的图片
				.setFailureDrawableId(R.mipmap.ic_launcher)
				//设置使用缓存
				.setUseMemCache(true)
				//设置支持gif
				.setIgnoreGif(false)
				//设置显示圆形图片
				.setCircular(true).build();
		x.image().bind(img3, "http://img1.3lian.com/2015/w22/55/d/107.jpg", options);

		//设置第二张图片属性的options
		ImageOptions options2 = new ImageOptions.Builder()
				//设置图片的大小
				.setSize(DensityUtil.dip2px(120), DensityUtil.dip2px(120))
				//设置边角的圆形
				.setRadius(DensityUtil.dip2px(5))
				//创建
				.build();

		x.image().bind(img4, "http://pic1.5442.com/2013/0801/07/05.jpg", options2);
	}

	@Override
	protected String[] initPermissions() {
		return new String[0];
	}
}
